/*
 * xstdio.h
 *
 *  Created on: 15 sept. 2011
 *      Author: lindenb
 */

#ifndef XSTDIO_H_
#define XSTDIO_H_
#include <cstdio>
#include <iostream>

class Reader
	{
	protected:
		char* buffer;
		std::size_t buffer_size;
		Reader();
	public:
		virtual ~Reader();
		virtual int eof()=0;
		virtual void close()=0;
		virtual int getc()=0;
		virtual char* readLine();
	};

class StdioReader:public Reader
	{
	private:
		bool owner;
		std::FILE* in;
	public:
		StdioReader();//stdin
		StdioReader(std::FILE* in);
		StdioReader(const char* filename);
		virtual int eof();
		virtual ~StdioReader();
		virtual void close();
		virtual int getc();

	};

std::FILE* safeFOpen(const char* filename,const char* mode);

class IOUtils
	{
	public:
		static bool fileExists(const char* s);
		static void copyTo(std::FILE* in, std::ostream& out);
		static void copyTo(std::FILE* in,std::FILE* out);
		static void copyFileTo(const char*, std::ostream& out);
		static std::string readFileContent(const char* s);
	};

#endif /* XSTDIO_H_ */
